export const userAddFormRulesMixin = {
  data() {
    // 验证邮箱的规则
    var checkEmail = (rule, value, callback) => {
      const regEmail = /^\w+@\w+(\.\w+)+$/; // 验证邮箱的正则表达式
      if (regEmail.test(value)) {
        return callback(); // 合法邮箱
      }
      // 返回一个错误提示
      callback(new Error('请输入合法的邮箱'));
    };
    // 验证手机的规则
    var checkMobeli = (rule, value, callback) => {
      const regMobile = /^1[3456789]\d{9}$/;
      const cs = /^(\d+[a-z]+)|([a-z]+\d+)$/gm;
      if (regMobile.test(value)) {
        return callback();
      }
      // 返回一个错误提示
      callback(new Error('请输入合法的手机号码'));
    };
    return {
      // 添加表单的验证规则对象
      addFormRules: {
        username: [
          { required: true, message: '请输入登录名称', trigger: 'blur' },
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          },
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          {
            min: 6,
            max: 15,
            message: '用户名长度在 6 到 15 个字符',
            trigger: 'blur',
          },
        ],
        email: [
          { required: true, message: '请输入邮箱', trigger: 'blur' },
          { validator: checkEmail, trigger: 'blur' },
        ],
        mobile: [
          { required: true, message: '请输入手机', trigger: 'blur' },
          { validator: checkMobeli, trigger: 'blur' },
        ],
      },
      // 修改用户数据验证规则
      editFormRules: {
        email: [
          { required: true, message: '请输入用户邮箱', trigger: 'blur' },
          { validator: checkEmail, trigger: 'blur' },
        ],
        mobile: [
          { required: true, message: '请输入用户手机', trigger: 'blur' },
          { validator: checkMobeli, trigger: 'blur' },
        ],
      },
    };
  },
};
export const rolesFormRulesMixin = {
  addFormRules: {
    Name: [
      { required: true, message: '请输入角色名字', trigger: 'blur' },
      {
        min: 2,
        max: 10,
        message: '输入的范围是 2 ~ 10 为字符',
        triggetr: 'nlur',
      },
    ],
    Desc: [
      { required: false, message: '请输入角色描述', trigger: 'blur' },
      {
        min: 5,
        max: 20,
        message: '输入的范围是 5 ~ 20 为字符',
        triggetr: 'nlur',
      },
    ],
  },
  editFormRules: {
    Name: [
      { required: true, message: '请输入角色名字', trigger: 'blur' },
      {
        min: 2,
        max: 10,
        message: '输入的范围是 2 ~ 10 为字符',
        triggetr: 'nlur',
      },
    ],
    Desc: [
      { required: false, message: '请输入角色描述', trigger: 'blur' },
      {
        min: 5,
        max: 20,
        message: '输入的范围是 5 ~ 20 为字符',
        triggetr: 'nlur',
      },
    ],
  },
};
export const paramsFormRulesMixin = {
  data() {
    return {
      // 添加表单的验证规则
      addFormRules: {
        attr_name: [
          { required: true, message: '请输入添加的分类', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '长度在 2 到 10 个字符',
            trigger: 'blur',
          },
        ],
      },
      // 修改表单的验证
      editFormRules: {
        attr_name: [
          { required: true, message: '请输入修改的信息', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '长度在 2 到 10 个字符',
            trigger: 'blur',
          },
        ],
      },
    };
  },
};
export const goodsAddFormRulesMixin = {
  data() {
    return {
      // 添加商品验证规则
      addFormRules: {
        goods_name: [
          { required: true, message: '请输入商品的名称', trigger: 'blur' },
          {
            min: 2,
            max: 30,
            message: '请输入 2 ~ 30 范围的字符',
            trigger: 'blur',
          },
        ],
        goods_price: [
          { required: true, message: '请输入商品的价格', trigger: 'blur' },
        ],
        goods_weight: [
          { required: true, message: '请输入商品的重量', trigger: 'blur' },
        ],
        goods_number: [
          { required: true, message: '请输入商品的数量', trigger: 'blur' },
        ],
        goods_cat: [
          { required: true, message: '请选择商品分类', trigger: 'blur' },
        ],
      },
    };
  },
};
export const palnsFormRulesMixin = {
  // 添加预案验证规则
  addFormRules: {
    name: [{ required: true, message: '请输入预案名称', trigger: 'blur' }],
    activityCode: [
      {
        required: true,
        message: '请输入活动名称',
        trigger: 'change',
        type: 'number',
      },
    ],
    content: [{ required: true, message: '请输入预案名称', trigger: 'blur' }],
  },
  editFormRules: {
    name: [{ required: true, message: '请输入预案名称', trigger: 'blur' }],
    activityCode: [
      {
        required: true,
        message: '请输入活动名称',
        trigger: 'change',
        type: 'number',
      },
    ],
    content: [{ required: true, message: '请输入预案名称', trigger: 'blur' }],
  },
};
export const telbookFormRulesMixin = {
  // 添加通讯录验证规则
  addFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    BlockCoding: [{ required: true, message: '请输入分组', trigger: 'change' }],
    Telephone: [
      { required: true, message: '请输入联系方式', trigger: 'blur' },
      { min: 11, max: 11, message: '请输入正确的联系方式', trigger: 'blur' },
    ],
  },
  editFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    BlockCoding: [{ required: true, message: '请输入分组', trigger: 'change' }],
    Telephone: [
      { required: true, message: '请输入联系方式', trigger: 'blur' },
      { min: 11, max: 11, message: '请输入正确的联系方式', trigger: 'blur' },
    ],
  },
};
export const hospitalFormRulesMixin = {
  // 添加验证规则
  addFormRules: {
    ChineseName: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    ActivityCode: [
      { required: true, message: '请选择活动', trigger: 'change' },
    ],
  },
  editFormRules: {
    ChineseName: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    ActivityCode: [
      { required: true, message: '请选择活动', trigger: 'change' },
    ],
  },
};
export const rightsFormRulesMixin = {
  // 添加预案验证规则
  addFormRules: {
    authName: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    level: [{ required: true, message: '请输入等级', trigger: 'blur' }],
    pid: [{ required: true, message: '请输入父节点', trigger: 'blur' }],
    area: [{ required: true, message: '请输入模块', trigger: 'blur' }],
    order: [{ required: true, message: '请输入顺序号', trigger: 'blur' }],
  },
  editFormRules: {
    authName: [{ required: true, message: '请输入名称', trigger: 'plur' }],
    level: [{ required: true, message: '请选择等级', trigger: 'change' }],
    pid: [{ required: true, message: '请输入父节点', trigger: 'change' }],
    area: [{ required: true, message: '请输入模块', trigger: 'change' }],
    order: [{ required: true, message: '请输入顺序号', trigger: 'blur' }],
  },
};
let isMobileNumber = (rule, value, callback) => {
  if (!value) {
    return new Error('请输入电话号码');
  } else {
    const reg = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
    const isPhone = reg.test(value);
    value = Number(value); //转换为数字
    if (typeof value === 'number' && !isNaN(value)) {
      //判断是否为数字
      value = value.toString(); //转换成字符串
      if (value.length < 0 || value.length > 12 || !isPhone) {
        //判断是否为11位手机号
        callback(new Error('手机号码格式如:138xxxx8754'));
      } else {
        callback();
      }
    } else {
      callback(new Error('请输入电话号码'));
    }
  }
};
let isPassWord = (rule, value, callback) => {
  if (!value) {
    return new Error('密码不能为空！');
  } else {
    const reg = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[A-Za-z\d@$!%*#?&._]{8,16}$/;
    const isPhone = reg.test(value);
    if (isPhone) {
      callback();
    } else {
      callback(
        new Error('密码由字母大小写、数字、符号三种组成并且长度大于8位'),
      );
    }
  }
};
export const medicalPersonFormRulesMixin = {
  // 添加人员验证规则
  addFormRules: {
    WorkCode: [{ required: true, message: '请输入工号', trigger: 'blur' }],
    Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
    ActivityCode: [{ required: true, message: '请输入活动', trigger: 'blur' }],
    PassWord: [
      { required: true, message: '请输入密码', trigger: 'blur' },
      { validator: isPassWord, trigger: 'blur' },
    ],
    Type: [{ required: true, message: '请输入角色', trigger: 'change' }],
    Telephone: [
      { required: true, message: '请输入手机号码', trigger: 'blur' },
      {
        required: false,
        validator: isMobileNumber,
        type: 'number',
        message: '输入正确的格式！',
        trigger: 'nlur',
      },
    ],
  },
  // 修改人员验证规则
  editFormRules: {
    WorkCode: [{ required: true, message: '请输入工号', trigger: 'blur' }],
    Name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
    PassWord: [{ required: true, message: '请输入密码', trigger: 'blur' }],
    ActivityCode: [{ required: true, message: '请输入活动', trigger: 'blur' }],
    Type: [{ required: true, message: '请输入角色', trigger: 'change' }],
    Telephone: [
      { required: true, message: '请输入手机号码', trigger: 'blur' },
      {
        required: false,
        validator: isMobileNumber,
        type: 'number',
        message: '输入正确的格式！',
        trigger: 'nlur',
      },
    ],
  },
};
export const ambulanceFormRulesMixin = {
  // 添加车辆验证规则
  addFormRules: {
    ActivityCode: [
      { required: true, message: '请输入活动', trigger: 'change' },
    ],
    ActivityVenuesCode: [
      { required: true, message: '请输入场馆', trigger: 'change' },
    ],
    CityCode: [{ required: true, message: '请输入城市', trigger: 'change' }],
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    Code: [{ required: true, message: '请输入编码', trigger: 'blur' }],
    StateCode: [{ required: true, message: '请输入状态', trigger: 'change' }],
  },
  // 修改车辆验证规则
  editFormRules: {
    ActivityCode: [
      { required: true, message: '请输入活动', trigger: 'change' },
    ],
    ActivityVenuesCode: [
      { required: true, message: '请输入场馆', trigger: 'change' },
    ],
    CityCode: [{ required: true, message: '请输入城市', trigger: 'change' }],
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    Code: [{ required: true, message: '请输入编码', trigger: 'blur' }],
    StateCode: [{ required: true, message: '请输入状态', trigger: 'change' }],
  },
};
export const drugsFormRulesMixin = {
  // 添加药品验证规则
  addFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    Type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
    Unit: [{ required: true, message: '请选择单位', trigger: 'change' }],
  },
  // 修改药品验证规则
  editFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    Type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
    Unit: [{ required: true, message: '请选择单位', trigger: 'change' }],
  },
};

export const activityFormRulesMixin = {
  // 添加药品验证规则
  addFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    StartTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
    EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
  },
  // 修改药品验证规则
  editFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    StartTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
    EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
  },
};
export const venuesFormRulesMixin = {
  // 添加场馆验证规则
  addFormRules: {
    ActivityCode: [
      { required: true, message: '请输入活动', trigger: 'change' },
    ],
    CityCode: [{ required: true, message: '请输入城市', trigger: 'change' }],
    CHIDescription: [
      { required: true, message: '请输入中文描述', trigger: 'blur' },
    ],
    StartTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
    EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
  },
  // 修改场馆验证规则
  editFormRules: {
    ActivityCode: [
      { required: true, message: '请输入活动', trigger: 'change' },
    ],
    CityCode: [{ required: true, message: '请输入城市', trigger: 'change' }],
    CHIDescription: [
      { required: true, message: '请输入中文描述', trigger: 'blur' },
    ],
    StartTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
    EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
  },
};
export const scheduleFormRulesMixin = {
  // 添加修改赛程的规则
  addFormRules: {
    ActivityCode: [
      { required: true, message: '请输入活动', trigger: 'change' },
    ],
    CityCode: [{ required: true, message: '请输入城市', trigger: 'change' }],
    VenuesCode: [{ required: true, message: '请输入场馆', trigger: 'blur' }],
    MatchName: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    StartTime: [{ required: true, message: '请输入开始时间', trigger: 'blur' }],
    EndTime: [{ required: true, message: '请输入结束时间', trigger: 'blur' }],
  },
};
export const medicalPointFormRulesMixin = {
  // 添加验证规则
  addFormRules: {
    VenuesCode: [{ required: true, message: '请选择场馆', trigger: 'change' }],
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    ActivityCode: [
      { required: true, message: '请选择活动', trigger: 'change' },
    ],
    Type: [{ required: true, message: '请输入角色', trigger: 'change' }],
    CityCode: [{ required: true, message: '请选择城市', trigger: 'change' }],
  },
  // 修改验证规则
  editFormRules: {
    VenuesCode: [{ required: true, message: '请选择场馆', trigger: 'change' }],
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    ActivityCode: [
      { required: true, message: '请选择活动', trigger: 'change' },
    ],
    Type: [{ required: true, message: '请输入角色', trigger: 'change' }],
    CityCode: [{ required: true, message: '请选择城市', trigger: 'change' }],
  },
};
export const dictionaryFormRulesMixin = {
  // 添加验证规则
  addFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    ID: [{ required: true, message: '请输入编码', trigger: 'blur' }],
    TypeID: [{ required: true, message: '请输入类型', trigger: 'change' }],
    SN: [{ required: true, message: '请输入顺序号', trigger: 'blur' }],
    ParentID: [{ required: true, message: '请输入上级编码', trigger: 'blur' }],
  },
  // 修改验证规则
  editFormRules: {
    Name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    ID: [{ required: true, message: '请输入编码', trigger: 'blur' }],
    TypeID: [{ required: true, message: '请输入类型', trigger: 'change' }],
    SN: [{ required: true, message: '请输入顺序号', trigger: 'blur' }],
    ParentID: [{ required: true, message: '请输入上级编码', trigger: 'blur' }],
  },
};
export const dictionaryBlockFormRulesMixin = {
  // 添加验证规则
  addFormRules: {
    Description: [{ required: true, message: '请输入名称', trigger: 'blur' }],

    TypeID: [{ required: true, message: '请输入类型', trigger: 'change' }],
  },
  // 修改验证规则
  editFormRules: {
    Description: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    TypeID: [{ required: true, message: '请输入类型', trigger: 'change' }],
  },
};
export const surplusFormRulesMixin = {
  // 添加验证规则
  addFormRules: {
    Description: [{ required: true, message: '请输入名称', trigger: 'blur' }],

    TypeID: [{ required: true, message: '请输入类型', trigger: 'change' }],
  },
  // 修改验证规则
  editFormRules: {
    Description: [{ required: true, message: '请输入名称', trigger: 'blur' }],
    TypeID: [{ required: true, message: '请输入类型', trigger: 'change' }],
  },
};
export const reportMedicalPointFormRulesMixin = {
  // 添加验证规则
  searchFormRules: {
    startTime: [{ required: true, message: '请输入时间', trigger: 'blur' }],
    endTime: [{ required: true, message: '请输入时间', trigger: 'blur' }],
    // medicalPoint: [
    //   { required: true, message: '请输入医疗点', trigger: 'change' },
    // ],
  },
};
const rTime = (time) => {
  var date = time ? new Date(time) : new Date();
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? '0' + m : m;
  var d = date.getDate();
  d = d < 10 ? '0' + d : d;
  var h = date.getHours();
  h = h < 10 ? '0' + h : h;
  var minute = date.getMinutes();
  minute = minute < 10 ? '0' + minute : minute;
  var s = date.getSeconds();
  s = s < 10 ? '0' + s : s;
  return y + '-' + m + '-' + d;
};
let isLeagleEndTime = (rule, value, callback) => {
  if (!value) {
    return new Error('请输入结束日期');
  } else {
    //现在日期
    let dateNow = new Date(rTime()).getTime();
    let dateValue = new Date(rTime(value)).getTime();
    console.info(dateNow, dateValue, new Date().getTime());
    if (dateNow < dateValue) {
      callback(new Error('结束日期不能大于当前日期'));
    } else {
      callback();
    }
  }
};

export const reportAsiaInfactFormRulesMixin = {
  // 添加验证规则
  searchFormRules: {
    startTime: [{ required: true, message: '请输入日期', trigger: 'blur' }],
    endTime: [
      {
        required: true,

        message: '请输入日期',
        trigger: 'change',
      },
    ],
    // citycode: [{ required: true, message: '请输入城市', trigger: 'change' }],
  },
};
//病历
export const patientFormRulesMixin = {
  // 修改病历修改验证规则
  updateFormRules: {
    Name: [{ required: true, message: '请输入患者姓名', trigger: 'blur' }],
  },
};
